<template>
  <el-header>
    <div class="l-content">
      <!-- 图标的展示 -->
      <el-button size="small" plain>
        <el-icon :size="20" @click="menuStore.Ustate()"><Menu /></el-icon>
      </el-button>
      <el-breadcrumb separator="/" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="store.currentMenu.path" v-if="current">{{
          current.label
        }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="user" :src="getImgSrc('touxiang')" alt="" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handelLoginOut()">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script setup>
import { useMenuStore } from "../stores/menu";
import { SelectMenu } from "../stores/menu";
import { computed, onMounted } from "vue";
import { useRouter } from "vue-router";
const menuStore = useMenuStore();
let store = SelectMenu();

const getImgSrc = (user) => {
  return new URL(`../assets/image/${user}.jpeg`, import.meta.url).href;
};
//计算属性
const current = computed(() => {
  return store.currentMenu;
});
onMounted(() => {
  store.changeCurrentMenu();
});
const router = useRouter();
const state = SelectMenu();
const handelLoginOut = () => {
  state.clearMenu();
  state.clearUser();
  router.push("/login");
};
</script>

<style scoped>
header {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  background-color: white;
  border-bottom: 1px solid #eee;
  padding: 0 20px;
}
.el-dropdown-link:focus {
  outline: none;
}
.user {
  width: 40px;
  border-radius: 50%;
}
.l-content {
  display: flex;
  align-items: center;
  color: white;
}
.l-content .el-button {
  margin-right: 10px;
}
.bread :deep(span) {
  cursor: pointer !important;
}
</style>
